package com.weiqiao.mall.repository.impl;

import com.weiqiao.base.dao.impl.BaseMongoDaoImpl;
import com.weiqiao.mall.repository.IReceiptRepository;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("ReceiptRepositoryImpl")
public class ReceiptRepositoryImpl extends BaseMongoDaoImpl implements IReceiptRepository {

    private String collectionName = "app_user_receipt_";

    @Override
    public List<String> findReceipt(int company_id, Bson filter, Bson filterSort, Pageable pageable) {
        int page = pageable.getPageNumber();
        int limit = pageable.getPageSize();
        if (page == 0) {
            page = 1;
        }
        // 获取起始条数
        int skip = (page - 1) * limit;
        List<String> list = this.findFilterSortSkipLimit(collectionName + company_id, filter,
                filterSort, skip, limit);
        return list;
    }

    @Override
    public String queryOneReceiptById(int company_id, Bson filter) {
        return this.findOne(collectionName + company_id, filter);
    }

    @Override
    public boolean updateRecepits(int company_id, Bson filter, Document doc) {
        return this.updateMany(collectionName + company_id, filter, doc, false);
    }

    @Override
    public List<String> queryOneReceiptByIds(int company_id, Bson filter) {
        return this.findFilter(collectionName + company_id, filter);
    }

    @Override
    public boolean updateOne(int company_id, Bson filter, String json) {
        return super.updateOne(collectionName + company_id, filter, json, false);
    }

    @Override
    public List<String> findAll(int company_id, Bson filter) {
        return super.findFilter(collectionName + company_id, filter);
    }
}
